package com.qianchang.microfinance.view.mine.loan;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.dm.library.widgets.OneLineLinearLayout;
import com.dm.library.widgets.element.DTextView;
import com.qianchang.microfinance.R;
import com.qianchang.microfinance.bean.MortgageGoodsBean;
import com.qianchang.microfinance.utils.GetJsonDataUtil;
import com.qianchang.microfinance.view.base.BaseRecyclerAdapter;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by jinbailiang on 2017/8/15.
 */

public class MortgageGoodsInfoAdapter extends BaseRecyclerAdapter<MortgageGoodsBean> {


    public MortgageGoodsInfoAdapter(Context context) {
        super(context, BaseRecyclerAdapter.ONLY_FOOTER);
    }

    @Override
    protected MyViewHolder onCreateDefaultViewHolder(ViewGroup parent, int type) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.adapter_mortgage_goods_info, parent, false);
        return new MyViewHolder(view);
    }

    @Override
    public int getItemViewType(int position) {
        return super.getItemViewType(position);
    }

    @Override
    protected void onBindDefaultViewHolder(RecyclerView.ViewHolder holder, final MortgageGoodsBean item, int position) {
        MyViewHolder vh = (MyViewHolder) holder;
        String type = item.getTypeName();
        vh.tvMortgageType.setTextContent(type);

        if ("0".equals(item.getType())) {
            String collateralNum = item.getCollateralNum();
            String powerNum = item.getPowerNum();
            String powerName = item.getPowerName();
            String commonMode = item.getCommonMode();
            String buildArea = item.getBuildArea();
            String usage = item.getUsage();
            String provinceId = item.getProvinceId();
            String cityId = item.getCityId();
            String countyId = item.getCountyId();
            String address = item.getAddress();
            String status = item.getStatus();


            vh.ollMortgageGoodsNo.setLeftContent("押品编号");
            vh.ollCertificateNo.setLeftContent("权属证书编号");
            vh.ollOwner.setLeftContent("权属人");
            vh.ollCommonMode.setLeftContent("使用用途");
            vh.ollBuiltUpArea.setLeftContent("建筑面积");
            vh.ollPurpose.setLeftContent("共有方式");
            vh.ollBelongCity.setLeftContent("所在城市");
            vh.ollAddressDetail.setLeftContent("详细地址");
            vh.ollMortgageGoodsStatus.setLeftContent("押品状态");

            vh.ollMortgageGoodsNo.setRightContent(collateralNum);
            vh.ollCertificateNo.setRightContent(powerNum);
            vh.ollOwner.setRightContent(powerName);
            vh.ollCommonMode.setRightContent(commonMode);
            vh.ollBuiltUpArea.setRightContent(buildArea + "平方米");
            vh.ollPurpose.setRightContent(usage);
            vh.ollBelongCity.setRightContent(GetJsonDataUtil.newInstance().getPrinceAndCityById(provinceId, cityId) + GetJsonDataUtil.newInstance().getAreaById(countyId));
            vh.ollAddressDetail.setRightContent(address);
            vh.ollMortgageGoodsStatus.setRightContent(status);
        } else {
            String collateralNum = item.getCollateralNum();
            String barnd = item.getBrand();
            String vehicleType = item.getVehicleType();
            String frameNum = item.getFrameNum();
            String engineNum = item.getEngineNum();
            String color = item.getColour();
            String evaluateDate = item.getEvaluateDate();
            String evaluateAmount = item.getEvaluateAmount();
            String status = item.getStatus();

            vh.ollMortgageGoodsNo.setLeftContent("押品编号");
            vh.ollCertificateNo.setLeftContent("车辆品牌");
            vh.ollOwner.setLeftContent("车辆型号");
            vh.ollCommonMode.setLeftContent("车架号");
            vh.ollBuiltUpArea.setLeftContent("发动机号");
            vh.ollPurpose.setLeftContent("车身颜色");
            vh.ollBelongCity.setLeftContent("出厂日期");
            vh.ollAddressDetail.setLeftContent("购买价格");
            vh.ollMortgageGoodsStatus.setLeftContent("押品状态");

            vh.ollMortgageGoodsNo.setRightContent(collateralNum);
            vh.ollCertificateNo.setRightContent(barnd);
            vh.ollBuiltUpArea.setRightContent(vehicleType);
            vh.ollOwner.setRightContent(frameNum);
            vh.ollCommonMode.setRightContent(engineNum);
            vh.ollPurpose.setRightContent(color);
            vh.ollBelongCity.setRightContent(evaluateDate);
            vh.ollAddressDetail.setRightContent(evaluateAmount);
            vh.ollMortgageGoodsStatus.setRightContent(status);
        }

//        frameNum;        //车辆识别代码/车架号
//        vehicleType;     //车辆型号
//        engineNum;       //发动机号
//        private String agencieCode; //发动机号
//        private String evaluateAmount;
//        private String evaluateDate;
    }


    static class MyViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.tv_mortgage_type)
        DTextView tvMortgageType;
        @BindView(R.id.oll_mortgage_goods_no)
        OneLineLinearLayout ollMortgageGoodsNo;
        @BindView(R.id.oll_certificate_no)
        OneLineLinearLayout ollCertificateNo;
        @BindView(R.id.oll_owner)
        OneLineLinearLayout ollOwner;
        @BindView(R.id.oll_common_mode)
        OneLineLinearLayout ollCommonMode;
        @BindView(R.id.oll_built_up_area)
        OneLineLinearLayout ollBuiltUpArea;
        @BindView(R.id.oll_purpose)
        OneLineLinearLayout ollPurpose;
        @BindView(R.id.oll_belong_city)
        OneLineLinearLayout ollBelongCity;
        @BindView(R.id.oll_address_detail)
        OneLineLinearLayout ollAddressDetail;
        @BindView(R.id.oll_mortgage_goods_status)
        OneLineLinearLayout ollMortgageGoodsStatus;

        MyViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
